package com.ruoyi.system.execution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.execution.domain.ContractExecutionRecords;
import com.ruoyi.system.execution.service.IContractExecutionRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同执行Controller
 * 
 * @author ruoyi
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/execution/execution")
public class ContractExecutionRecordsController extends BaseController
{
    @Autowired
    private IContractExecutionRecordsService contractExecutionRecordsService;

    /**
     * 查询合同执行列表
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractExecutionRecords contractExecutionRecords)
    {
        startPage();
        List<ContractExecutionRecords> list = contractExecutionRecordsService.selectContractExecutionRecordsList(contractExecutionRecords);
        return getDataTable(list);
    }

    /**
     * 导出合同执行列表
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:export')")
    @Log(title = "合同执行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractExecutionRecords contractExecutionRecords)
    {
        List<ContractExecutionRecords> list = contractExecutionRecordsService.selectContractExecutionRecordsList(contractExecutionRecords);
        ExcelUtil<ContractExecutionRecords> util = new ExcelUtil<ContractExecutionRecords>(ContractExecutionRecords.class);
        util.exportExcel(response, list, "合同执行数据");
    }

    /**
     * 获取合同执行详细信息
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:query')")
    @GetMapping(value = "/{executionId}")
    public AjaxResult getInfo(@PathVariable("executionId") Long executionId)
    {
        return success(contractExecutionRecordsService.selectContractExecutionRecordsByExecutionId(executionId));
    }

    /**
     * 新增合同执行
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:add')")
    @Log(title = "合同执行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractExecutionRecords contractExecutionRecords)
    {
        return toAjax(contractExecutionRecordsService.insertContractExecutionRecords(contractExecutionRecords));
    }

    /**
     * 修改合同执行
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:edit')")
    @Log(title = "合同执行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractExecutionRecords contractExecutionRecords)
    {
        return toAjax(contractExecutionRecordsService.updateContractExecutionRecords(contractExecutionRecords));
    }

    /**
     * 删除合同执行
     */
    @PreAuthorize("@ss.hasPermi('execution:execution:remove')")
    @Log(title = "合同执行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{executionIds}")
    public AjaxResult remove(@PathVariable Long[] executionIds)
    {
        return toAjax(contractExecutionRecordsService.deleteContractExecutionRecordsByExecutionIds(executionIds));
    }
}
